package com.allenkerr.util;

import com.allenkerr.third.HistogramRetrieval;
import org.junit.Test;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;

/**
 * Created by 小柯 on 17/7/7.
 */
//@RunWith(SpringRunner.class)
//@SpringBootTest
public class PerceptualHashTest_1 {

    @Test
    public void test1() throws IOException {
//        InputStream aFile = HistogramRetrieval.class.getResourceAsStream("/images/25-边牧(小图).jpeg");
//        InputStream aFile = HistogramRetrieval.class.getResourceAsStream("/images/after-01.jpg");
        InputStream aFile = HistogramRetrieval.class.getResourceAsStream("/images/before-01.jpg");
//        InputStream aFile = HistogramRetrieval.class.getResourceAsStream("/images/787.jpg");

//        InputStream bFile = HistogramRetrieval.class.getResourceAsStream("/images/25-边牧.jpeg");
//        InputStream bFile = HistogramRetrieval.class.getResourceAsStream("/images/after-04.jpg");
        InputStream bFile = HistogramRetrieval.class.getResourceAsStream("/images/before-02.jpg");
//        InputStream bFile = HistogramRetrieval.class.getResourceAsStream("/images/787-旋转缩小.jpg");

        BufferedImage aPic = ImageIO.read(aFile);
        BufferedImage bPic = ImageIO.read(bFile);

        double dHash = PerceptualHash_1.hammingDistanceFromDHash(aPic, bPic);
        System.out.println("dHash = " + dHash);

        double pHash = PerceptualHash_1.hammingDistanceFromPHash(aPic, bPic);
        System.out.println("pHash = " + pHash);
        /**
         * 分界点 4
         * (16 - 4) / 16 = 0.75
         *
         * after-01 vs after-04
         * dHash = 0.8125
         * pHash = 0.6875
         *
         * 边牧
         * dHash = 0.6875
         * pHash = 0.9375
         *
         * before-01 vs before-02
         * dHash = 0.9375
         * pHash = 0.625
         */
    }

}